package org.apache.connector.http;

import com.sun.security.ntlm.Server;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;

public class HttpConnector {
    boolean stop;
    private String scheme = "http";

    public void start() {
        Runnable r = () -> {
            ServerSocket serverSocket = null;
            try {
                serverSocket = new ServerSocket(80, 5, InetAddress.getByName("127.0.0.1"));
            } catch (IOException e) {
                e.printStackTrace();
                System.exit(1);
            }
            Socket socket = null;
            while (!stop) {
                try {
                    socket = serverSocket.accept();
                } catch (IOException e) {
                    e.printStackTrace();
                    continue;
                }
                HttpProcessor httpProcessor = new HttpProcessor(this);
                httpProcessor.process(socket);
            }
        };
        Thread t = new Thread(r);
        t.start();
    }
}
